package com.rimi.lzhg.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 基于layui定义的响应数据对象
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class ResponseEntity implements Serializable {

    private Integer code=0;
    private String msg;
    private Long count;
    private Object  data;

    public static ResponseEntity error(String msg){
        return new ResponseEntity(500,msg);
    }

    public static  ResponseEntity success(String msg){
        return new ResponseEntity(0,msg);
    }

    /**
     * @param count  count为数据总条数
     * @param data   data为分页的数据
     * @return  封装响应对象
     */
    public static ResponseEntity success(int count,Object data){
        return new ResponseEntity((long)count,data);
    }

    /**
     * 适用于只返回一个参数或对象时使用
     * @param data  对象数据
     * @return  封装响应对象
     */
    public static ResponseEntity success(Object data){
        return success(1,data);
    }

    ResponseEntity(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    ResponseEntity(Long count, Object data) {
        this.count = count;
        this.data = data;
    }
}
